package com.vip.jwt.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vip.jwt.common.entity.R;
import com.vip.jwt.entity.Role;
import com.vip.jwt.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author vip
 * @since 2021-05-04
 */
@RestController
@RequestMapping("/api/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @PostMapping
    public Object addRole(@RequestBody Role role){
        roleService.saveRole(role);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public Object deleteById(@PathVariable String id){
        roleService.deleteById(id);
        return R.ok();
    }

    @PutMapping
    public Object updateRole(@RequestBody Role role){
        roleService.updateRole(role);
        return R.ok();
    }

    @GetMapping
    public Object list(){
        List<Role> roles = roleService.list();
        return R.ok().data("data",roles);
    }

    @GetMapping("/{page}/{limit}")
    public Object getPage(@PathVariable Long page,@PathVariable Long limit){
        Page<Role> rolePage = new Page<>(page,limit);
        Page<Role> roles = roleService.page(rolePage);
        return R.ok().data("data",roles);
    }

}

